package leetcode.Y2024M6.study;

import leetcode.Y2024M6.TreeNode;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class S530 {
    private List<Integer> list = new ArrayList<>();

    public int getMinimumDifference(TreeNode root) {
        preview(root);
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < list.size(); i++) {
            min = Math.min(min, list.get(i) - list.get(i - 1));
        }
        return min;

    }

    private int preview(TreeNode root) {
        if (root == null) return 0;
        preview(root.left);
        list.add(root.val);
        preview(root.right);
        return 1;
    }

    @Test
    public void test() {
        int[] root={4,2,6,1,3};
        System.out.println(getMinimumDifference(TreeNode.createTree(root)));
    }
}
